﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PowerWaveAddin.UserControls
{
    public partial class UploadProgressControl : UserControl
    {
        public delegate void AddOperationToListDelegate(string operationName);
        public AddOperationToListDelegate AddOperationToList;

        public delegate void SetLastOperationStatusDelegate(string newStatus);
        public SetLastOperationStatusDelegate SetLastOperationStatus;

        public delegate void SetProgressPercentageDelegate(int percent);
        public SetProgressPercentageDelegate SetProgressPercentage;


        public UploadProgressControl()
        {
            this.AddOperationToList = new AddOperationToListDelegate(AddOperationToListImpl);
            this.SetLastOperationStatus = new SetLastOperationStatusDelegate(SetLastOperationStatusImpl);
            this.SetProgressPercentage = new SetProgressPercentageDelegate(SetProgressPercentageImpl);
            InitializeComponent();
        }

        private void AddOperationToListImpl(string operationName)
        {
            this.operationList.Items.Add(operationName);
        }

        private void SetLastOperationStatusImpl(string newStatus)
        {
            ListViewItem item = this.operationList.Items[this.operationList.Items.Count - 1];
            string mainValue = item.Text;
            item.SubItems.Clear();
            item.Text = mainValue;
            item.SubItems.Add(newStatus);
            this.operationList.Items[this.operationList.Items.Count - 1] = item;
        }

        private void SetProgressPercentageImpl(int percent)
        {
            this.progressBar.Value = percent;
        }
    }
}
